package com.java.model;
import java.util.HashMap;
import java.util.Map;
import java.io.Serializable;
<<<<<<< HEAD
=======
import java.util.function.BiConsumer;
>>>>>>> 1985484ee1452c7d22a8520a807bdae2011c4a07

public class Student implements Serializable{
    //学生姓名，id，年龄，班级，年级，成绩,绩点，政治面貌
    private String name;
    private String id;
    private int age;
    private String className;
    private String grade;
    private Map<String, Double> scores; // 科目 -> 分数
    private double gpa;
    private String politicalStatus;
<<<<<<< HEAD
    public String[] password;
    private String username;

    // 构造方法,初始化
    public Student(String id, String name, String grade, int age,double gpa,String className,String politicalStatus,String... password) {
        this.id = id;
        this.name = name != null ? name : "";
=======
    // 构造方法,初始化
    public Student(String id, String name, String grade, int age,double gpa,String className,String politicalStatus) {
        this.id = id;
        this.name = name;
>>>>>>> 1985484ee1452c7d22a8520a807bdae2011c4a07
        this.age = age;
        this.grade = grade;
        this.gpa = gpa;
        this.className = className;
<<<<<<< HEAD
        this.password = password;
        this.scores = new HashMap<>();
    }

    public Student(String username, String password) {
        this.username = username;
        this.name = username != null ? username : ""; // 避免 name 为 null
        this.password = password.split(",");
    }

    public  Student setName(String username, String[] password) {
        this.username = username;
        this.password = password;
        return this;
    }


=======
        this.scores = new HashMap<>();
    }
>>>>>>> 1985484ee1452c7d22a8520a807bdae2011c4a07
    // 添加或更新课程成绩
    public void addOrUpdateCourseGrade(String className, double grade) {
        scores.put(className,grade);
    }

    // 删除课程成绩
    public void removeCourseGrade(String className) {
        scores.remove(className);
    }

<<<<<<< HEAD
=======
    // 获取平均分
    public double getAverageGrade() {
        double total=0;
        int count=0;
        for (Map.Entry<String, Double> stringDoubleEntry : scores.entrySet()) {
            double socre=stringDoubleEntry.getValue();
            total+=socre;
            count++;
        }
        return total/count;
    }
    // 获取最高分
    public double getHighestGrade() {
        double max=0;
        for (Map.Entry<String, Double> stringDoubleEntry : scores.entrySet()) {
            double socre=stringDoubleEntry.getValue();
            if(socre>max)
                max=socre;
        }
        return max;
    }

    // 获取最低分
    public double getLowestGrade() {
        double min=0;
        for (Map.Entry<String, Double> stringDoubleEntry : scores.entrySet()) {
            double socre=stringDoubleEntry.getValue();
            if(min>socre)
                min=socre;
        }
        return min;
    }

    // 获取特定课程成绩
    public Double getGradeForCourse(String className) {

        return null;
    }
>>>>>>> 1985484ee1452c7d22a8520a807bdae2011c4a07
    //getter和setter方法


    public String getName() {
        return name;
    }

    public void setName(String name) {
<<<<<<< HEAD
        this.name = name != null ? name : "";

=======
        this.name = name;
>>>>>>> 1985484ee1452c7d22a8520a807bdae2011c4a07
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public Map<String, Double> getScores() {
        return scores;
    }

    public void setScores(Map<String, Double> scores) {
        this.scores = scores;
    }

    public double getGpa() {
        return gpa;
    }

    public void setGpa(double gpa) {
        this.gpa = gpa;
    }

    public String getPoliticalStatus() {
        return politicalStatus;
    }

    public void setPoliticalStatus(String politicalStatus) {
        this.politicalStatus = politicalStatus;
    }

    @Override
    public String toString() {
        return name + " (" + id + ")";
    }
<<<<<<< HEAD

    public Double getGradeForCourse(String course) {
        return Double.valueOf(0);

    }
=======
>>>>>>> 1985484ee1452c7d22a8520a807bdae2011c4a07
}
